﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GestorDocument.Model.IRepository;

namespace GestorDocument.DAL.Repository
{
    public class BitacoraRepository : IBitacora
    {
        public void InsertBitacora(Model.BitacoraModel bitacora)
        {
            using (var entity = new GestorDocumentEntities())
            {
                if (bitacora != null)
                {
                    //Validar si el elemento ya existe
                    BITACORA_ERROR result = null;
                    try
                    {
                        result = (from o in entity.BITACORA_ERROR
                                  where o.IdBitacora == bitacora.IdBitacora
                                  select o).First();
                    }
                    catch (Exception ex)
                    {
                        ;
                    }


                    if (result == null)
                    {
                        entity.BITACORA_ERROR.AddObject(
                            new BITACORA_ERROR()
                            {
                                IdBitacora = bitacora.IdBitacora,
                                Msg = bitacora.Msg
                            }
                       );
                        
                       entity.SaveChanges();

                    }
                }
            }
        }
    }
}